let vm = new Vue({
    el: "#content",
    data: {
        depts: [],
        user: {},
        focus: 0
    },
    methods: {
        findDept: function () {
            axios({
                method: 'get',
                url: "/dept"
            }).then(res => {
                if (res.data.flag) {
                    this.depts = res.data.data;
                } else {
                    layer.msg(res.data.message);
                }
            });
        },
        findUser: function () {
            axios({
                method: "get",
                url: `/user/detail/${this.user.id}`
            }).then(res => {
                if (res.data.flag) {
                    this.user = res.data.data.user;
                    this.focus = res.data.data.focus;
                } else {
                    layer.msg(res.data.message);
                }
            })
        },
        updateUser: function () {
            axios({
                method: "put",
                url: "/user/update",
                data: this.user
            }).then(res => {
                layer.msg(res.data.message);
                if (res.data.flag) {
                    localStorage.setItem("loginUser", JSON.stringify(res.data.data));
                }
            });
        },
        uploadPic: function () {
            let form = new FormData();
            form.append("file", document.getElementById("picFile").files[0]);
            axios({
                method: "post",
                url: "/user/uploadPic",
                headers: {
                    'content-type': 'multipart/form-data'
                },
                data: form
            }).then(res => {
                layer.msg(res.data.message);
                if (res.data.flag) {
                    this.user = res.data.data;
                    localStorage.setItem("loginUser", JSON.stringify(this.user));
                    location.reload();
                }
            })
        }
    },
    created: function () {
        this.user = JSON.parse(localStorage.getItem("loginUser"));
        this.findDept();
        this.findUser();
    }
})